library(tidyverse)## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.7 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(ggplot2)
library(readr)
library(knitr)
library(plotly)##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
Introduction
Main body
Australia and New zealand
annual_number_of_deaths_by_cause <- read_csv("Data/annual-number-of-deaths-by-cause.csv",
col_types = cols(`Number of executions` = col_double()))## Warning: One or more parsing issues, see `problems()` for details
life_expectancy <- read_csv("Data/life-expectancy.csv")## Rows: 19028 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Entity, Code
## dbl (2): Year, Life expectancy
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
share_with_depression <- read_csv("Data/share-with-depression.csv")## Rows: 6780 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Entity, Code
## dbl (2): Year, Depressive disorders
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
1.List all kinds of death causes
world_data <-annual_number_of_deaths_by_cause %>%
filter(!is.na(Code),
Year %in% c(1990:2018)) %>%
pivot_longer(cols = -c(1:3),
names_to = "Death_cause",
values_to = "Count") %>%
group_by(Year,Death_cause) %>%
summarise(Death_amount=sum(Count, na.rm = TRUE))## `summarise()` has grouped output by 'Year'. You can override using the
## `.groups` argument.
world_data %>% filter(Year==1990) %>%
pull(Death_cause) %>%
kable(caption = "The caueses of death")| x |
|---|
| Acute hepatitis |
| Alcohol use disorders |
| Alzheimer’s disease and other dementias |
| Cardiovascular diseases |
| Chronic kidney disease |
| Chronic respiratory diseases |
| Cirrhosis and other chronic liver diseases |
| Conflict and terrorism |
| Diabetes mellitus |
| Diarrheal diseases |
| Digestive diseases |
| Drowning |
| Drug use disorders |
| Environmental heat and cold exposure |
| Exposure to forces of nature |
| Fire, heat, and hot substances |
| HIV/AIDS |
| Interpersonal violence |
| Lower respiratory infections |
| Malaria |
| Maternal disorders |
| Meningitis |
| Neonatal disorders |
| Neoplasms |
| Number of executions |
| Nutritional deficiencies |
| Parkinson’s disease |
| Poisonings |
| Protein-energy malnutrition |
| Road injuries |
| Self-harm |
| Terrorism (deaths) |
| Tuberculosis |
For this table@ref(tab:deathcauses),
2.World data
world_data %>%
filter(Year==2018) %>%
arrange(desc(Death_amount)) %>%
head() %>%
kable(caption = "The world' top six causes of death in 2018")| Year | Death_cause | Death_amount |
|---|---|---|
| 2018 | Cardiovascular diseases | 36237930 |
| 2018 | Neoplasms | 19588775 |
| 2018 | Chronic respiratory diseases | 7774886 |
| 2018 | Digestive diseases | 5031882 |
| 2018 | Lower respiratory infections | 4974611 |
| 2018 | Neonatal disorders | 3885798 |
p1 <- ggplot(world_data,
mapping = aes(x=Year,
y=Death_amount,
color=Death_cause))+
geom_line()+
theme_bw()
ggplotly(p1)Number of deaths by cause, World, 1990 to 2019
@ref(fig:worldplot)
3.Australia and New Zealand data
(1).Select death due to disease factors
disease_data <- annual_number_of_deaths_by_cause %>%
select(1,3,5,6,7,8,9,12,13,14,15,16,17,18,22,24,26,27,32,33,34,36) %>%
filter(Country %in% c("Australia","Switzerland"),
Year %in% c(1990:2018)) %>%
pivot_longer(cols = -c(1:3),
names_to = "Death_cause",
values_to = "Count")
AZ_life_expectancy <- life_expectancy %>% filter(
Entity %in% c("Australia","Switzerland"),
Year %in% c(1990:2018)
) %>%
rename("Country" = "Entity",
"Life_expectancy" = "Life expectancy") %>%
select(-Code)
DL_data <- disease_data %>%
left_join(AZ_life_expectancy,by=c("Country","Year"))
p2 <-ggplot(DL_data,
mapping = aes(x=Year,
y=Count,
color=Death_cause))+
geom_line()+
geom_line(aes(y=Life_expectancy*500),
color="#1CDC4B",
size=1)+
geom_point(aes(y=Life_expectancy*500),
color="#12F09E",
size=1)+
scale_y_continuous(name = "Number of deaths by disease causes",
sec.axis = sec_axis(trans =~./500,
name = "Life expectancy"))+
facet_wrap(~Country,
scales = "free_y")+
theme_bw()
ggplotly(p2)Number of deaths by disease causes, 1990 to 2018
(2).select death due to other factors
other_data <- annual_number_of_deaths_by_cause %>%
select(1,3,4,10,11,19,20,21,23,25,28,29,30,31,35) %>%
filter(Country %in% c("Australia","Switzerland"),
Year %in% c(1990:2018)) %>%
pivot_longer(cols = -c(1:3),
names_to = "Death_cause",
values_to = "Count")
AZ_share_with_depression <-share_with_depression %>% filter(
Entity %in% c("Australia","Switzerland"),
Year %in% c(1990:2018)
) %>%
rename("Country" = "Entity",
"Depressive_disorders" = "Depressive disorders") %>%
select(-Code)
DD_data <- other_data %>%
left_join(AZ_share_with_depression,by=c("Country","Year"))
p3 <- ggplot(DD_data,
mapping = aes(x=Year,
y=Count,
color=Death_cause))+
geom_line()+
geom_line(aes(y=Depressive_disorders*300),
color="#2399F5",
size=1)+
geom_point(aes(y=Depressive_disorders*300),
color="#99C3E5",
size=1)+
scale_y_continuous(name = "Number of deaths by other causes",
sec.axis = sec_axis(trans =~./300,
name = "Depressive disorders %"))+
facet_wrap(~Country,
scales = "free_y")
ggplotly(p3)Number of deaths by other causes, 1990 to 2018
(ggplot?), Wickham et al. (2019),(readr?)
Colusion
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy
D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019.
“Welcome to the tidyverse.”
Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.